package com.heima.behavior.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.behavior.mapper.ApBehaviorEntryMapper;
import com.heima.behavior.service.ApBehaviorEntryService;
import com.heima.model.behavior.pojo.ApBehaviorEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ApBehaviorEntryServiceImpl extends ServiceImpl<ApBehaviorEntryMapper,ApBehaviorEntry> implements ApBehaviorEntryService {
    @Override
    public ApBehaviorEntry findByUserIdOrEquipmentId(Integer userId, Integer equipmentId) {
        //根据用户id查新实体
        if (userId != null){
            ApBehaviorEntry apBehaviorEntry = this.getOne(Wrappers.<ApBehaviorEntry>lambdaQuery()
                    .eq(ApBehaviorEntry::getEntryId, userId)
                    .eq(ApBehaviorEntry::getType, ApBehaviorEntry.Type.USER.getCode()));
            return apBehaviorEntry;
        }
        //根据设备id查询
        if (equipmentId !=null){
            return this.getOne(Wrappers.<ApBehaviorEntry>lambdaQuery()
                    .eq(ApBehaviorEntry::getEntryId,equipmentId)
                    .eq(ApBehaviorEntry::getType,ApBehaviorEntry.Type.EQUIPMENT));
        }
        return null;
    }
}
